﻿Public Class LoginControl
    Private Sub LoginButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LoginButton.Click
        MPQClient.Username = UsernameTextBox.Text
        If SingleGameOnly Then
            MPQClient.Server.RegisterClient(1)
        Else
            MPQClient.Server.DoLogin(UsernameTextBox.Text, PasswordTextBox.Text)
        End If

        LoginButton.Enabled = False
        CreateUserButton.Enabled = False
        UsernameTextBox.Enabled = False
        PasswordTextBox.Enabled = False
    End Sub

    Private Sub CreateUserButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CreateUserButton.Click
        If Not UsernameTextBox.Text = "" Then
            MPQClient.Username = UsernameTextBox.Text
            MPQClient.Server.CreateUser(UsernameTextBox.Text, PasswordTextBox.Text)
        End If
    End Sub

    Private Sub LoginControl_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        With My.Application.CommandLineArgs
            If .Contains("/u") Then
                UsernameTextBox.Text = .Item(.IndexOf("/u") + 1)
                If .Contains("/p") Then
                    PasswordTextBox.Text = .Item(.IndexOf("/p") + 1)
                End If
                LoginButton.PerformClick()
            End If
        End With

        If SingleGameOnly Then
            PasswordTextBox.Visible = False
            Label2.Visible = False
            CreateUserButton.Visible = False
        End If

        If FirstPlay Then
            TutorialControl1.ShowAndMoveOn()
        End If
    End Sub
End Class
